package upc.edu.poo;

import static org.junit.Assert.*; 
import org.junit.Before;
import org.junit.Test; 
import java.util.Iterator;



public class SprintPlanTest {
    public SprintPlan sprintplan = new SprintPlan();
    public SprintRepository sprintrepository = new SprintRepository();
	
	@Before
	public void inicio(){
		// Registrar Team
		assertEquals(true,sprintplan.EnviaTeam(sprintplan.CreaTeam("0","Ninguno"), sprintrepository));
		assertEquals(true,sprintplan.EnviaTeam(sprintplan.CreaTeam("1","Joel Santos"), sprintrepository));
		assertEquals(true,sprintplan.EnviaTeam(sprintplan.CreaTeam("2","Cesar Rosas"), sprintrepository));
		assertEquals(true,sprintplan.EnviaTeam(sprintplan.CreaTeam("3","Noel Rojas"), sprintrepository));
		
		// Registrar Prioridad de Orden
		assertEquals(true,sprintplan.EnviaOrder(sprintplan.CreaOrder("10","Urgente"), sprintrepository));
		assertEquals(true,sprintplan.EnviaOrder(sprintplan.CreaOrder("20","Normal"), sprintrepository));
		assertEquals(true,sprintplan.EnviaOrder(sprintplan.CreaOrder("30","Bajo"), sprintrepository));			
	}
	
	
	@Test
	public void TestSP() {
		/*
		 * Registra el Sprint SprintId; FechaInicio; FechaFinal; Estado;
		 * OrderId;ProductBacklogId;RestrospectiveID;ReviewMeetingID;MemberId;
		 */
		assertEquals(true, sprintplan.EnviaSprint(sprintplan.CreaSprint("1",
				"1", "01/01/2012", "31/01/2012", "A", "0", "0", "0", "0", "0"),
				sprintrepository));
		assertEquals(true, sprintplan.EnviaSprint(sprintplan.CreaSprint("2",
				"2", "01/02/2012", "29/02/2012", "A", "00", "0", "0", "0", "0"),
				sprintrepository));
		assertEquals(true, sprintplan.EnviaSprint(sprintplan.CreaSprint("3",
				"3", "01/03/2012", "31/03/2012", "A", "00", "0", "0", "0", "0"),
				sprintrepository));
		assertEquals(true, sprintplan.EnviaSprint(sprintplan.CreaSprint("4",
				"4", "01/04/2012", "31/04/2012", "A", "00", "0", "0", "0", "0"),
				sprintrepository));
		assertEquals(true, sprintplan.EnviaSprint(sprintplan.CreaSprint("5",
				"5", "01/05/2012", "31/05/2012", "A", "00", "0", "0", "0", "0"),
				sprintrepository));
		// Muestra la Carga del Sprint
		ListarSprint();
		/* Asignar el Nro. 10 Prioridad al Sprint */
		Sprint sprint = new Sprint();
		sprint = sprintplan.CreaSprint("4","4", "01/04/2012", "31/04/2012", "A", "10", "0", "0", "0", "0");		
		assertEquals(true,sprintplan.AsignarPrioridadSprint(sprint, sprintrepository));
		/* Asignar el Codigo del Team Nro. 1 al Sprint */		 
		sprint = sprintplan.CreaSprint("4","4", "01/04/2012", "31/04/2012", "A", "10", "0", "0", "0", "1");		
		assertEquals(true,sprintplan.AsignarTeam(sprint, sprintrepository));
		
		// Elimina un Sprint
		assertEquals(true, sprintplan.EliminaSprint("1", sprintrepository));
		// Muestra la Carga del Sprint despues de Eliminar
		ListarSprint();
		

	}

	public void TestProductBacklog(){
		
	}
	
    private void ListarSprint()
    {
		System.out.println("SprintID     F.Inicio     F.Final Estado  Prioridad  Responsable");

		Iterator<java.util.Map.Entry<String, Sprint>> it = sprintrepository.Sprint
				.entrySet().iterator();
		StringBuilder mostrar = new StringBuilder();

		while (it.hasNext()) {
			java.util.Map.Entry<String, Sprint> pair = it.next();
			mostrar.append(pair.getValue().getSprintId() + "          "  
					+ pair.getValue().getFechaInicio()   + "  "
					+ pair.getValue().getFechaFinal()    + "   "
					+ pair.getValue().getEstado()        + "       "
					+ pair.getValue().getOrderId()       + "          "					
					+ pair.getValue().getMemberId() + "." + 
					sprintrepository.Team.get(pair.getValue().getMemberId()).getMemberNombre()
					+ "\n" );
		}

		System.out.println(mostrar);

	}

}
